package com.example.demo.dao;


import com.example.demo.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author liuxianchun
 * @date 2021/1/19
 */
@Repository
public interface ShoppingCartDao {

    @Update("update shoppingcart set num=#{num} where userId=#{userId} and productId=#{productId}")
    void updateShoppingCart(int userId,int productId,int num);

    @Insert("insert into shoppingcart(userId,productId,num) values(#{userId},#{productId},1)")
    void addShoppingCart(int userId,int productId);

    @Select("select * from shoppingcart where userId=#{userId} and productId=#{productId}")
    ShoppingCart findShoppingCart(int userId, int productId);

    @Select("select * from shoppingcart where userId=#{userId}")
    List<ShoppingCart> getShoppingCart(int userId);

    @Delete("delete from shoppingcart where userId=#{userId} and productId=#{productId}")
    void deleteShoppingCart(int userId,int productId);

}
